/*
 * @Author: wjj3
 * @Date: 2022-11-23 15:28:18
 * @Description: 查用户、查流程
 */
import { map } from 'lodash-es';
import URL_PATH from '@/api/interface-urls/common';
import {
  getDatas,
  postData,
  list,
  getDatasObjectParam,
} from '@/api/data-source/commonRequestApi';

class BizMaintainService {
  // 查用户
  static username = (param) => postData(URL_PATH.USER_NAME, param);

  // 查流程
  static flowPath = (param) => postData(URL_PATH.FLOW_PATH, param);

  // 保存用户权限
  static jurisdiction = (param) => postData(URL_PATH.JURISDICTION, param);

  // 数据回显
  static getEcho = (userId) => getDatas(URL_PATH.ECHO, { userId });

  // 文种数据
  static getArts = (param) => list(URL_PATH.ARTS_LIST, param);

  // 所有公文
  static getArrWork = (param) => getDatasObjectParam(URL_PATH.ALL_WORK, param);

  static getCurrentNode = (piid) => getDatas(URL_PATH.GET_CURRENT_NODE, { piid });

  // 获取所有按钮
  static getBtns = async () => {
    const data = await getDatas(URL_PATH.ALL_BTNS);
    const res = data.filter((t) => t?.custom?.includes('isMaintainType'));
    return map(res, (t) => {
      let custom;
      try {
        custom = t.custom && JSON.parse(t.custom);
      } catch {
        custom = t.custom;
      }
      return {
        label: t.operatorName,
        event: t.operatorFlag,
        icon: t.icon,
        sort: t.sort,
        custom,
        show: custom?.display !== 'none',
        loading: false,
      };
    });
  };

  // 修改标题工单
  static revampTitle = (param) => postData(URL_PATH.REVAMP_TITLE, param);
}

export default BizMaintainService;
